home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / AHDI / TESTSPAR / CMDBLK.S < prev    next >
Encoding:
Text File  |  2001-02-09  |  11.2 KB  |  391 lines

  1. ;+
  2. ; Edit History
  3. ;
  4. ; May-19-89    ml.    Started this with.
  5. ; Sep-14-89    ml.    Make sure transfer length in d1 for rqsense()
  6. ;            is non-0 before entering _dorcmd().  Else there
  7. ;            will a divide by zero in _dorcmd().
  8. ;-
  9.  
  10. .include    "defs.h"
  11.  
  12. .extern    _doscmd        ; do a simple command.  No DMA involved.
  13. .extern    _dorcmd        ; do a receive command.  DMA data back.
  14. .extern    _dowcmd        ; do a write command.  DMA data away.
  15.  
  16.  
  17. ;+
  18. ; OPCODES for standard SCSI and ACSI commands
  19. ;-
  20. TSTUNT    equ    $00
  21. RZUNT    equ    $01
  22. RQSEN    equ    $03
  23. FMTUNT    equ    $04
  24. RABLK    equ    $07
  25. READ    equ    $08
  26. WRITE    equ    $0a
  27. SEEK    equ    $0b
  28. INQRY    equ    $12
  29. MDSEL    equ    $15
  30. RLEAS    equ    $17
  31. MDSEN    equ    $1a
  32. STUNIT    equ    $1b
  33. RDIAG    equ    $1c
  34. SDIAG    equ    $1d
  35. RMEDIA    equ    $1e
  36. RDCAP    equ    $25        ; SCSI only
  37. XREAD    equ    $28        ; SCSI only
  38. XWRT    equ    $2a        ; SCSI only
  39. XSEEK    equ    $2b        ; SCSI only
  40. VERIFY    equ    $2f        ; SCSI only
  41. RDDFCT    equ    $37        ; SCSI only
  42. WRTBUF    equ    $3b        ; SCSI only
  43. RDBUF    equ    $3c        ; SCSI only
  44.  
  45. ;+
  46. ; EQUATES
  47. ;-
  48. NCMD        equ    6    ; normal command length (6 bytes)
  49. LCMD        equ    10    ; extended command length (10 bytes)
  50.  
  51. ;+
  52. ; DECLARATIONS
  53. ;-
  54.         .globl    _cmdblk
  55. _cmdblk:    dcb.b    10,0    ; command block
  56. .even
  57.  
  58.  
  59. ;+
  60. ; untrdy() - set up and send command block of the TEST UNIT READY command.
  61. ;
  62. ; untrdy(pdev)
  63. ; WORD    pdev;        $4(sp).w
  64. ;-
  65.     .globl    _untrdy
  66. _untrdy:
  67.     bsr    clrcmdblk        ; clear command block
  68.     lea    _cmdblk,a0        ; a0 -> beginning of command block
  69.     move.b    #TSTUNT,(a0)        ; byte 0 = TSTUNT opcode
  70.                     ; byte 1-5 = reserved
  71.     move.w    $4(sp),d0        ; d0 = physical unit number
  72.     moveq    #NCMD,d2        ; d2 = length of command
  73.     bsr    _doscmd            ; send the command
  74.     rts
  75.  
  76.  
  77. ;+
  78. ; rqsense() - set up and send command block of the REQUEST SENSE command.
  79. ;          (only the lsb of len is used)
  80. ;
  81. ; rqsense(pdev, len, buf)
  82. ; WORD    pdev;        $4(sp).w    ; physical unit number
  83. ; WORD    len;        $6(sp).w    ; amount of sense data (in bytes)
  84. ; BYTE    *buf;        $8(sp).l    ; buffer for sense data
  85. ;-
  86.     .globl    _rqsense
  87. _rqsense:
  88.     bsr    clrcmdblk        ; clear command block
  89.     lea    _cmdblk,a0        ; a0 -> beginning of command block
  90.     move.b    #RQSEN,(a0)        ; byte 0 = RQSEN opcode
  91.     move.b    $7(sp),4(a0)        ; byte 4 = allocation length 
  92.                     ; byte 1-3 and 5 = reserved
  93.     moveq    #4,d1            ; request at least 4 bytes
  94.     cmp.w    $6(sp),d1        ; requesting < 4 bytes?
  95.     bcc.s    .0            ; if so, request 4 bytes
  96.     move.w    $6(sp),d1        ; else d1 = requested len (in #bytes)
  97. .0:    move.w    $4(sp),d0        ; d0 = physical unit number
  98.     moveq    #NCMD,d2        ; d2 = length of command
  99.     movea.l    $8(sp),a0        ; a0 = buffer for sense data
  100.     bsr    _dorcmd            ; send the command
  101.     rts
  102.  
  103.  
  104. .if    !DRIVER                ; not to be included in driver
  105.  
  106. ;+
  107. ; format() - set up and send command block of the FORMAT UNIT command.
  108. ;
  109. ; format(pdev, interleave)
  110. ; WORD    pdev;        $4(sp).w
  111. ; WORD    interleave    $6(sp).w
  112. ;-
  113.     .globl    _format
  114.     .extern    _doformat
  115. _format:
  116.     bsr    clrcmdblk        ; clear command block
  117.     lea    _cmdblk,a0        ; a0 -> beginning of command block
  118.     move.b    #FMTUNT,(a0)        ; byte 0 = FMTUNT opcode
  119.     move.b    $6(sp),3(a0)        ; byte 3 = interleave (msb)
  120.     move.b    $7(sp),4(a0)        ; byte 4 = interleave (lsb)
  121.                     ; byte 1-2 = unused; byte 5 = reserved
  122.     move.w    $4(sp),d0        ; d0 = physical unit number
  123.     moveq    #NCMD,d2        ; d2 = length of command
  124.     bsr    _doformat        ; send the command
  125.     rts
  126.  
  127. .endif    ;!DRIVER
  128.  
  129. ;+
  130. ; hread() - set up and send command block of the READ command.
  131. ;
  132. ; hread(sectnum, count, buf, pdev)
  133. ; LONG    sectnum        4(sp).l
  134. ; WORD    count        8(sp).w
  135. ; BYTE    *buf;        $a(sp).l    $b(sp)=high $c(sp)=mid $d(sp)=low
  136. ; WORD    pdev;        $e(sp).w
  137. ;-
  138.     .globl    _hread
  139. _hread:    lea    _cmdblk,a0        ; a0 -> beginning of command block
  140.     move.b    #READ,(a0)+        ; byte 0 = READ opcode
  141.     move.b    5(sp),(a0)+        ; byte 1 = msb of logical block addr
  142.     move.b    6(sp),(a0)+        ; byte 2 = logical block addr
  143.     move.b    7(sp),(a0)+        ; byte 3 = lsb of logical block addr
  144.     move.b    9(sp),(a0)+        ; byte 4 = transfer length (in blocks)
  145.     clr.b    (a0)            ; byte 5 = control byte
  146.     move.w    $e(sp),d0        ; d0 = physical unit number
  147.     moveq    #0,d1            ; clear d1
  148.     move.w    8(sp),d1        ; d1 = transfer length (in bytes)
  149.     lsl.l    #8,d1            ;    = # blocks * 512
  150.     add.l    d1,d1
  151.     moveq    #NCMD,d2        ; d2 = length of command
  152.     movea.l    $a(sp),a0        ; a0 = read buffer
  153.     bsr    _dorcmd            ; send the command
  154.     rts
  155.  
  156.  
  157. ;+
  158. ; hwrite() - set up and send command block of the WRITEcommand.
  159. ;
  160. ; hwrite(sectnum, count, buf, pdev)
  161. ; LONG    sectnum        4(sp).l
  162. ; WORD    count        8(sp).w
  163. ; BYTE    *buf;        $a(sp).l    $b(sp)=high $c(sp)=mid $d(sp)=low
  164. ; WORD    pdev;        $e(sp).w
  165. ;-
  166.     .globl    _hwrite
  167. _hwrite:
  168.     lea    _cmdblk,a0        ; a0 -> beginning of command block
  169.     move.b    #WRITE,(a0)+        ; it's a read; byte 0 = READ opcode
  170.     move.b    5(sp),(a0)+        ; byte 1 = msb of logical block addr
  171.     move.b    6(sp),(a0)+        ; byte 2 = logical block addr
  172.     move.b    7(sp),(a0)+        ; byte 3 = lsb of logical block addr
  173.     move.b    9(sp),(a0)+        ; byte 4 = transfer length (in blocks)
  174.     clr.b    (a0)            ; byte 5 = control byte
  175.     move.w    $e(sp),d0        ; d0 = physical unit number
  176.     moveq    #0,d1            ; clear d1
  177.     move.w    8(sp),d1        ; d1 = transfer length (in bytes)
  178.     lsl.l    #8,d1
  179.     add.l    d1,d1
  180.     moveq    #NCMD,d2        ; d2 = length of command
  181.     movea.l    $a(sp),a0        ; a0 = write buffer
  182.     bsr    _dowcmd            ; send the command
  183.     rts
  184.  
  185.  
  186. ;+
  187. ; inquiry() - set up and send command block of the INQUIRY command.
  188. ;
  189. ; inquiry(pdev, len, buf)
  190. ; WORD    pdev;        $4(sp).w    ; physical unit number
  191. ; WORD    len;        $6(sp).w    ; amount requested (in bytes)
  192. ; BYTE    *buf;        $8(sp).l    ; buffer for inquiry data
  193. ;-
  194.     .globl    _inquiry
  195. _inquiry:
  196.     bsr    clrcmdblk        ; clear command block
  197.     lea    _cmdblk,a0        ; a0 -> beginning of command block
  198.     move.b    #INQRY,(a0)        ; byte 0 = INQRY opcode
  199.     move.b    $7(sp),4(a0)        ; byte 4 = allocation length 
  200.                     ; byte 1-3 and 5 = reserved
  201.     move.w    $4(sp),d0        ; d0 = physical unit number
  202.     moveq    #0,d1            ; clear d1
  203.     move.w    $6(sp),d1        ; d1.l = transfer length (in bytes)
  204.     moveq    #NCMD,d2        ; d2 = length of command
  205.     movea.l    $8(sp),a0        ; a0 = buffer for sense data
  206.     bsr    _dorcmd            ; send the command
  207.     rts
  208.  
  209.  
  210. .if    !DRIVER                ; not to be included in driver
  211.  
  212. ;+
  213. ; mdselect() - set up and send command block of the MODE SELECT command.
  214. ;
  215. ; mdselect(pdev, len, buf)
  216. ; WORD    pdev;        $4(sp).w    ; physical unit number
  217. ; WORD    len;        $6(sp).w    ; parameter list length (in bytes)
  218. ; BYTE    *buf;        $8(sp).l    ; buffer for inquiry data
  219. ;-
  220.     .globl    _mdselect
  221. _mdselect:
  222.     bsr    clrcmdblk        ; clear command block
  223.     lea    _cmdblk,a0        ; a0 -> beginning of command block
  224.     move.b    #MDSEL,(a0)        ; byte 0 = MDSEL opcode
  225.     move.b    $7(sp),4(a0)        ; byte 4 = parameter list length 
  226.                     ; byte 1-3 and 5 = reserved
  227.     move.w    $4(sp),d0        ; d0 = physical unit number
  228.     moveq    #0,d1            ; clear d1
  229.     move.w    $6(sp),d1        ; d1.l = transfer length (in #bytes)
  230.     moveq    #NCMD,d2        ; d2 = length of command
  231.     movea.l    $8(sp),a0        ; a0 = buffer for sense data
  232.     bsr    _dowcmd            ; send the command
  233.     rts
  234.  
  235.  
  236. ;+
  237. ; mdsense() - set up and send command block of the MODE SENSE command.
  238. ;
  239. ; mdsense(pdev, pcode, pcf, len, buf)
  240. ; WORD    pdev;        $4(sp).w    ; physical unit number
  241. ; WORD    pcode;        $6(sp).w    ; page code (must be 0 if ACSI)
  242. ; WORD    pcf;        $8(sp).w    ; pcf value (must be 0 if ACSI)
  243. ; WORD    len;        $a(sp).w    ; parameter list length (in bytes)
  244. ; BYTE    *buf;        $c(sp).l    ; buffer for inquiry data
  245. ;-
  246.     .globl    _mdsense
  247. _mdsense:
  248.     bsr    clrcmdblk        ; clear command block
  249.     move.w    8(sp),d0        ; d0 = pcf value
  250.     lsl.w    #6,d0            ; shift pcf value to bit 6 and 7
  251.     or.b    7(sp),d0        ; d0 = pcf value | pcode
  252.     lea    _cmdblk,a0        ; a0 -> beginning of command block
  253.     move.b    #MDSEN,(a0)        ; byte 0 = MDSEN opcode
  254.     move.b    d0,2(a0)        ; byte 2 = pcf | pcode
  255.     move.b    $b(sp),4(a0)        ; byte 4 = allocation length 
  256.                     ; byte 1,3 and 5 = reserved
  257.     move.w    $4(sp),d0        ; d0 = physical unit number
  258.     moveq    #0,d1            ; clear d1
  259.     move.w    $a(sp),d1        ; d1 = transfer length (in #bytes)
  260.     moveq    #NCMD,d2        ; d2 = length of command
  261.     movea.l    $c(sp),a0        ; a0 = buffer for sense data
  262.     bsr    _dorcmd            ; send the command
  263.     rts
  264.  
  265.  
  266. ;+
  267. ; stunit() - set up and send command block of the START/STOP UNIT command.
  268. ;
  269. ; stunit(pdev, flag)
  270. ; WORD    pdev;        $4(sp).w    ; physical unit number
  271. ; WORD    flag;        $6(sp).w    ; 0 - stop unit; 1 - start unit;
  272. ;-
  273.     .globl    _stunit
  274.     .extern    _dostunit
  275. _stunit:
  276.     bsr    clrcmdblk        ; clear command block
  277.     lea    _cmdblk,a0        ; a0 -> beginning of command block
  278.     move.b    #STUNIT,(a0)        ; byte 0 = STUNIT opcode
  279.     move.b    $7(sp),4(a0)        ; byte 4 = reserved + start/stop 
  280.                     ; byte 1-3 and 5 = reserved
  281.     move.w    $4(sp),d0        ; d0 = physical unit number
  282.     moveq    #NCMD,d2        ; d2 = length of command
  283.     bsr    _dostunit        ; send the command
  284.     rts
  285.  
  286.  
  287.  
  288. ;+
  289. ; readcap() - set up and send command block of the EXTENDED READ command.
  290. ;
  291. ; readcap(pdev, pmi, sectnum, buf)
  292. ; WORD    pdev;        4(sp).w
  293. ; WORD    pmi;        6(sp).w        (only low byte is used)
  294. ; LONG    sectnum;    8(sp).l
  295. ; BYTE    *buf;        $c(sp).l    $d(sp)=high $e(sp)=mid $f(sp)=low
  296. ;-
  297.     .globl    _readcap
  298. _readcap:
  299.     lea    _cmdblk,a0        ; a0 -> beginning of command block
  300.     move.b    #RDCAP,(a0)+        ; byte 0 = RDCAP opcode
  301.     clr.b    (a0)+            ; byte 1 = log unit # + reserved
  302.     move.l    8(sp),(a0)+        ; byte 2-5 = logical block addr
  303.     clr.b    (a0)+            ; byte 6 = reserved
  304.     clr.b    (a0)+            ; byte 7 = reserved
  305.     move.b    7(sp),(a0)+        ; byte 8 = partial medium indicator
  306.     clr.b    (a0)            ; byte 9 = reserved
  307.     move.w    $4(sp),d0        ; d0 = physical unit number
  308.     moveq    #8,d1            ; d1 = transfer length (in bytes)
  309.     moveq    #LCMD,d2        ; d2 = length of command
  310.     movea.l    $c(sp),a0        ; a0 = data buffer
  311.     bsr    _dorcmd            ; send the command
  312.     rts
  313.  
  314. .endif    ;!DRIVER
  315.  
  316.  
  317. ;+
  318. ; xtdread() - set up and send command block of the EXTENDED READ command.
  319. ;
  320. ; xtdread(sectnum, count, buf, pdev)
  321. ; LONG    sectnum        4(sp).l
  322. ; WORD    count        8(sp).w
  323. ; BYTE    *buf;        $a(sp).l    $b(sp)=high $c(sp)=mid $d(sp)=low
  324. ; WORD    pdev;        $e(sp).w
  325. ;-
  326.     .globl    _xtdread
  327. _xtdread:
  328.     lea    _cmdblk,a0        ; a0 -> beginning of command block
  329.     move.b    #XREAD,(a0)+        ; byte 0 = XREAD opcode
  330.     clr.b    (a0)+            ; byte 1 = unit number + reserved
  331.     move.l    4(sp),(a0)+        ; byte 2-5 = logical block addr
  332.     clr.b    (a0)+            ; byte 6 = reserved
  333.     move.b    8(sp),(a0)+        ; byte 7 = transfer length (msb)
  334.     move.b    9(sp),(a0)+        ; byte 8 = transfer length (lsb)
  335.     clr.b    (a0)            ; byte 9 = reserved
  336.     move.w    $e(sp),d0        ; d0 = physical unit number
  337.     moveq    #0,d1            ; clear d1
  338.     move.w    8(sp),d1        ; d1 = transfer length (in bytes)
  339.     lsl.l    #8,d1
  340.     add.l    d1,d1
  341.     moveq    #LCMD,d2        ; d2 = length of command
  342.     movea.l    $a(sp),a0        ; a0 = read buffer
  343.     bsr    _dorcmd            ; send the command
  344.     rts
  345.  
  346.  
  347. ;+
  348. ; xtdwrt() - set up and send command block of the EXTENDED READ command.
  349. ;
  350. ; xtdwrt(sectnum, count, buf, pdev)
  351. ; LONG    sectnum        4(sp).l
  352. ; WORD    count        8(sp).w
  353. ; BYTE    *buf;        $a(sp).l    $b(sp)=high $c(sp)=mid $d(sp)=low
  354. ; WORD    pdev;        $e(sp).w
  355. ;-
  356.     .globl    _xtdwrt
  357. _xtdwrt:
  358.     lea    _cmdblk,a0        ; a0 -> beginning of command block
  359.     move.b    #XWRT,(a0)+        ; byte 0 = XWRT opcode
  360.     clr.b    (a0)+            ; byte 1 = unit number + reserved
  361.     move.l    4(sp),(a0)+        ; byte 2-5 = logical block addr
  362.     clr.b    (a0)+            ; byte 6 = reserved
  363.     move.b    8(sp),(a0)+        ; byte 7 = transfer length (msb)
  364.     move.b    9(sp),(a0)+        ; byte 8 = transfer length (lsb)
  365.     clr.b    (a0)            ; byte 9 = reserved
  366.     move.w    $e(sp),d0        ; d0 = physical unit number
  367.     moveq    #0,d1            ; clear d1
  368.     move.w    8(sp),d1        ; d1 = transfer length (in bytes)
  369.     lsl.l    #8,d1
  370.     add.l    d1,d1
  371.     moveq    #LCMD,d2        ; d2 = length of command
  372.     movea.l    $a(sp),a0        ; a0 = write buffer
  373.     bsr    _dowcmd            ; send the command
  374.     rts
  375.  
  376.  
  377. ;+
  378. ; clrcmdblk()
  379. ;
  380. ; Clear the 10-byte command block
  381. ;-
  382. clrcmdblk:
  383.     lea    _cmdblk,a0        ; a0 = ptr to command block
  384.     clr.l    (a0)+
  385.     clr.l    (a0)+
  386.     clr.w    (a0)
  387.     rts
  388.  
  389.  
  390.  
  391.